package dao

import (
	"daily-blog/global"
	"daily-blog/model"
)

func CreatePostTags(postTags []model.PostTag) error {
	return global.GVA_DB.Create(&postTags).Error
}
func DeletePostTagsByPostId(postId string) error {
	return global.GVA_DB.Delete(&model.PostTag{}, "post_id=?", postId).Error
}
func GetPostTags() (postTags []model.PostTag, err error) {
	err = global.GVA_DB.Model(&model.PostTag{}).Select("post_id", "tag_id", "tag_name").Find(&postTags).Error
	return
}
func CreateTag(tag *model.Tag) error {
	return global.GVA_DB.Create(tag).Error
}
func DeleteTagById(tagId string) error {
	return global.GVA_DB.Delete(&model.Tag{}, "tag_id=?", tagId).Error
}
func GetTagList() (tagList []model.TagInfo, err error) {
	err = global.GVA_DB.Model(&model.Tag{}).Select("tag_id", "tag_name").Find(&tagList).Error
	return
}
func UpdateTagById(tagId, tagName string) error {
	return global.GVA_DB.Model(&model.Tag{}).Where("tag_id=?", tagId).Update("tag_name", tagName).Error
}
